package com.summer.peony.common.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.summer.peony.common.entity.AjaxResult;
import com.summer.peony.common.entity.AjaxResult.Type;

/**
 * @ClassName: ErrorExceptionHandler
 * @Description: TODO(异常处理类)
 * @author: TaoGe
 * @date: 2020年6月29日 下午1:51:27
 * @version: v0.0.1
 */
@ControllerAdvice
@RestController
public class ErrorExceptionHandler {

	private static final Logger logger = LoggerFactory.getLogger(ErrorExceptionHandler.class);

	/**
	 * 统一异常处理
	 * 
	 * @param exception exception
	 * @return
	 */
	@ExceptionHandler({ RuntimeException.class })
	@ResponseStatus(HttpStatus.OK)
	public AjaxResult processException(RuntimeException exception) {
		logger.info("自定义异常处理-RuntimeException");
		return new AjaxResult(Type.ERROR, "服务器异常");
	}

	/**
	 * 统一异常处理
	 * 
	 * @param exception exception
	 * @return
	 */
	@ExceptionHandler({ Exception.class })
	@ResponseStatus(HttpStatus.OK)
	public AjaxResult processException(Exception exception) {
		logger.info("自定义异常处理-Exception");
		return new AjaxResult(Type.ERROR, "服务器异常");
	}

}
